package com.ddiviewer;

//=============================================================================
// Imports
//=============================================================================
import java.util.Vector;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

//=============================================================================
// Begin Custom Adapter
//=============================================================================
class ItemAdapter extends ArrayAdapter<Item> {
	
	//=========================================================================
	// Variables
	//=========================================================================
	private String			Tab						= null;
	private String			Name					= null;
	private String			Level					= null;
	private String			Category				= null;
	private String			TierName				= null;
	private String			GroupRole				= null;
	private String			CombatRole				= null;
	private String			Prerequisite			= null;
	private String			EnhancementValue		= null;
	private String			DescriptionAttribute	= null;
	private TextView		label1					= null;
	private TextView		label2					= null;
	private TextView		label3					= null;
	private TextView		label4					= null;
	Vector<Item>			items					= null;


	//=========================================================================
	// Constructor
	//=========================================================================
	public ItemAdapter(Context context, int textViewResourceId, Vector<Item> items) {
		super(context, textViewResourceId, items);
		this.items = items;
	}
	
	
	//=============================================================================
	// getView()
	//=============================================================================
	@Override
	public View getView (int position, View convertView, ViewGroup parent) {
		View row = convertView;
		
		if (row == null) {
			LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	    	row = inflater.inflate(R.layout.list, null);
	    }
		
		Item i = items.elementAt(position);
		if (i != null) {    
		    
			label1		= (TextView) row.findViewById(R.id.listname);
		    label2		= (TextView) row.findViewById(R.id.listlevel);
		    label3		= (TextView) row.findViewById(R.id.listcategory);
		    label4		= (TextView) row.findViewById(R.id.listtab);
		   	
		   	Tab						= i.getTab();
		   	Name					= i.getName();
		   	Level					= i.getLevel();
		   	Category				= i.getCategory();
		   	TierName				= i.getTierName();
		   	GroupRole				= i.getGroupRole();
		   	CombatRole				= i.getCombatRole();
		   	Prerequisite			= i.getPrerequisite();
		   	EnhancementValue		= i.getEnhancementValue();
		   	DescriptionAttribute	= i.getDescriptionAttribute();

		   	if (Tab.equals("Class")) {
		   		label1.setText(Name);
		   		label2.setText("");
		   		label3.setText(Category);
		   		label4.setText(Tab);
		   	} else if (Tab.equals("EpicDestiny") || Tab.equals("ParagonPath")) {
		   		label1.setText(Name);
		   		label2.setText("");
		   		label3.setText("["+Prerequisite+"]");
		   		label4.setText(Tab);
		   	} else if (Tab.equals("Feat")) {
		   		label1.setText(Name);
		   		label2.setText(TierName);
		   		label3.setText(Category);
		   		label4.setText(Tab);
		   	} else if (Tab.equals("Item")) {
		   		if (EnhancementValue != null) label1.setText(Name + " (+" + EnhancementValue + ")"); else label1.setText(Name);
		   		if (Level != null) label2.setText("Level: " + Level); else label2.setText("");
		   		label3.setText(Category);
		   		label4.setText(Tab);
		   	} else if (Tab.equals("Power")) {
		   		label1.setText(Name);
		   		if (Level != null) label2.setText("Level: " + Level); else label2.setText("");
		   		label3.setText(Category);
		   		label4.setText(Tab);
		   	} else if (Tab.equals("Race")) {
		   		label1.setText(Name);
		   		label2.setText("");
		   		label3.setText(DescriptionAttribute);
		   		label4.setText(Tab);
		   	} else if (Tab.equals("Ritual")) {
		   		label1.setText(Name);
		   		if (Level != null) label2.setText("Level: " + Level); else label2.setText("");
		   		label3.setText(Category);
		   		label4.setText(Tab);
		   	} else if (Tab.equals("Skill")) {
		   		label1.setText(Name);
		   		if (Level != null) label2.setText("Level: " + Level); else label2.setText("");
		   		label3.setText(Category);
		   		label4.setText(Tab);
		   	} else if (Tab.equals("Monster")) {
		   		label1.setText(Name);
		   		if (Level != null) label2.setText("Level: " + Level); else label2.setText("");
		   		label3.setText("[" + GroupRole + "] " + CombatRole);
		   		label4.setText(Tab);
		   	} else if (Tab.equals("Glossary")) {
		   		label1.setText(Name);
		   		label2.setText("");
		   		label3.setText(Category);
		   		label4.setText(Tab);
		   	} else if (Tab.equals("Deity")) {
		   		label1.setText(Name);
		   		label2.setText("");
		   		label3.setText(Category);
		   		label4.setText(Tab);
		   	} else if (Tab.equals("Trap")) {
		   		label1.setText(Name);
		   		if (Level != null) label2.setText("Level: " + Level); else label2.setText("");
		   		label3.setText("[" + GroupRole + "]");
		   		label4.setText(Tab);
		   	}
		}	
	   	return row;
	   	
	}

}
//=============================================================================
// End Custom Adapter
//=============================================================================